var addVisitedInfoDlg = {addVisitedInfoData: {}, zTreeInstance: null, validateFields: {}};

//清除数据
addVisitedInfoDlg.clearData = function () {
    this.addVisitedInfoData = {};
};

//设置对话框中的数据 @param key 数据的名称 @param val 数据的具体值
addVisitedInfoDlg.set = function (key, val) {
    this.addVisitedInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
    return this;
};

//设置对话框中的数据 @param key 数据的名称 @param val 数据的具体值
addVisitedInfoDlg.get = function (key) {
    return $("#" + key).val();
};

//关闭此对话框
addVisitedInfoDlg.close = function () {
    parent.layer.close(parent.layer.getFrameIndex(window.name));
};

//显示部门选择的树 @returns
addVisitedInfoDlg.showaddVisitedSelectTree = function () {
    var pName = $("#pName");
    var pNameOffset = $("#pName").offset();
    $("#parentaddVisitedMenu").css({
        left: pNameOffset.left + "px",
        top: pNameOffset.top + pName.outerHeight() + "px"
    }).slideDown("fast");
    $("body").bind("mousedown", onBodyDown);
};

//隐藏部门选择的树
addVisitedInfoDlg.hideaddVisitedSelectTree = function () {
    $("#parentaddVisitedMenu").fadeOut("fast");
    $("body").unbind("mousedown", onBodyDown);// mousedown当鼠标按下就可以触发，不用弹起
};

//收集数据
addVisitedInfoDlg.collectData = function () {
    this.set('id').set('rid').set('customerName').set('economicAbility').set('pseudonym').set('customerPhone').set('customerSex').set('customerAge').set('ids')
        .set('birthday').set('customerStatus').set('referee').set('refereeShip').set('idCardNo').set('fixedTelephone')
        .set('qqNumber').set('wechatNumber').set('isHaveChildren').set('isReturnVisit').set('email').set('zipCode').set('identificationNumber')
        .set('numberOfAudits').set('finalAuditor').set('auditorTime').set('consumAbility').set('nonTransactionLevel').set('appointmentPayService')
        .set('transactionLevel').set('characters').set('consumptionHabits').set('otherContact').set('country').set('address')
        .set('province').set('cities').set('region').set('maritalStatus').set('occupation').set('filingTime').set('medicalRecordNumber')
        .set('arrivalTime').set('fieldTc').set('causeOfNoReturnVisit').set('entryClerk').set('recordPeople').set('reservationsId')
        .set('oneChannel').set('twoChannel').set('thrChannel').set('oneMedium').set('twoMedium').set('thrMedium')
        .set('archiving').set('toVoidremarks').set('remarks').set('actualAccountBalance').set('giveAccountBalance')
        .set('refundMoney').set('phoneSharShip').set('reservationsId').set('revisitContent').set('address');
};

//验证数据是否为空
addVisitedInfoDlg.validate = function () {
    $('#addVisitedInfoForm').data("bootstrapValidator").resetForm();
    $('#addVisitedInfoForm').bootstrapValidator('validate');
    return $("#addVisitedInfoForm").data('bootstrapValidator').isValid();
};

function onBodyDown(event) {
    if (!(event.target.id == "menuBtn" || event.target.id == "parentaddVisitedMenu" || $(
            event.target).parents("#parentaddVisitedMenu").length > 0)) {
        addVisitedInfoDlg.hideaddVisitedSelectTree();
    }
}

addVisitedInfoDlg.getEditd = function () {
    $(".modify").attr("readOnly", false);
    $(".modify").css("border", "1px solid #999999");
    $(".select_styles").removeAttr("disabled");
    $(".select_styles").css("border", "1px solid #999999");
    $("#remarks").attr("readOnly", false);
    if ($("#oneChannel").val() == "直接上门") {
        $(".select_styles1").removeAttr("disabled");
        $(".select_styles1").css("border", "1px solid #999999");
    }
};

//点击修改
modifyAppointment = function (ids) {
    var index = layer.open({
        type: 2,
        title: '修改预约客户',
        area: ['70%', '95%'],
        fix: true,
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/doctor_addTasks/' + ids
    });
    this.layerIndex = index;
};

subsequent = function (id) {
    var index = layer.open({
        type: 2,
        title: '复诊预约',
        area: ['70%', '95%'],
        fix: true,
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/subsequent_info/' + id + '/2'
    });
    this.layerIndex = index;
};

//发送短信
shortMessage = function (id) {
    var index = layer.open({
        type: 2,
        title: '发送消息',
        area: ['60%', '80%'],
        fix: true,
        maxmin: true,
        content: Feng.ctxPath + '/msgSend/to_msgSend/' + id
    });
    this.layerIndex = index;
};

$(function () {
    Feng.initValidator("addVisitedInfoForm", addVisitedInfoDlg.validateFields);
    var arrears = document.getElementsByClassName("arrears");
    for (var i = 0; i < arrears.length; i++) {
        if (arrears[i].innerHTML == 0) {
            arrears[i].style.color = "#666666"
        }
    }

    //成交记录下拉箭头
    $(".showDetails").click(function () {
        $(this).parent().siblings().toggle();
        $(this).children().toggle();
    });

    //储值交易
    depositTransaction = function () {
        $.ajax({
            url: Feng.ctxPath + "/consultant/getCustomerStatus/" + $("#customerId").val() ,
            dataType: "json",
            contentType: "application/json",
            type: "POST",
            success: function (data) {
                if (data.split(",")[0] == '复诊') {
                    alert("复诊不能进行储值操作！");
                    return;
                } else if (data.split(",")[2] == 2) {
                    alert("到店时间不是今天，不能进行储值操作！");
                    return;
                } else {
                    var customerId = $("#customerId").val();
                    var index = layer.open({
                        type: 2,
                        title: '储值交易',
                        area: ['40%', '65%'],
                        fix: true,
                        maxmin: true,
                        content: Feng.ctxPath + '/customer/depositTransaction/' + customerId
                    });
                    this.layerIndex = index;
                }
            }
        });
    };

    //储值交易记录
    transactionRecord = function () {
        var customerId = $("#customerId").val();
        var index = layer.open({
            type: 2,
            title: '储值交易记录',
            area: ['90%', '90%'],
            fix: true,
            maxmin: true,
            content: Feng.ctxPath + '/customer/transactionRecord/' + customerId
        });
        this.layerIndex = index;
    };


    //种植牙俱乐部交易
    orthodonticsTransaction = function () {
        $.ajax({
            url: Feng.ctxPath + "/consultant/getCustomerStatus/" + $("#customerId").val() ,
            dataType: "json",
            contentType: "application/json",
            type: "POST",
            success: function (data) {
                if (data.split(",")[0] == '复诊') {
                    alert("复诊不能进行操作！");
                    return;
                } else if (data.split(",")[2] == 2) {
                    alert("到店时间不是今天，不能进行操作！");
                    return;
                } else {
                    var customerId = $("#customerId").val();
                    var index = layer.open({
                        type: 2,
                        title: '种植牙俱乐部交易',
                        area: ['40%', '65%'],
                        fix: true,
                        maxmin: true,
                        content: Feng.ctxPath + '/customer/orthodonticsTransaction/' + customerId
                    });
                    this.layerIndex = index;
                }
            }
        });
    };

    //种植牙俱乐部交易记录
    orthodonticsTransactionRecord = function () {
        var customerId = $("#customerId").val();
        var index = layer.open({
            type: 2,
            title: '种植牙俱乐部交易记录',
            area: ['90%', '90%'],
            fix: true,
            maxmin: true,
            content: Feng.ctxPath + '/customer/orthodonticsTransactionRecord/' + customerId
        });
        this.layerIndex = index;
    };

    //积分交易
    integralAdjustment = function () {
        // $.ajax({
        //     url: Feng.ctxPath + "/consultant/getCustomerStatus/" + $("#customerId").val() ,
        //     dataType: "json",
        //     contentType: "application/json",
        //     type: "POST",
        //     success: function (data) {
        //         if (data.split(",")[0] == '复诊') {
        //             alert("复诊不能进行积分操作！");
        //             return;
        //         } else {
        var customerId = $("#customerId").val();
        var index = layer.open({
            type: 2,
            title: '积分录入',
            area: ['40%', '60%'],
            fix: true,
            maxmin: true,
            content: Feng.ctxPath + '/customer/integralAdjustment/' + customerId
        });
        this.layerIndex = index;
        // }
        // }
        // });
    };


    //返现转账
    returnCashTurn = function () {
        $.ajax({
            url: Feng.ctxPath + "/consultant/getCustomerStatus/" + $("#customerId").val(),
            dataType: "json",
            contentType: "application/json",
            type: "POST",
            success: function (data) {
                if (data.split(",")[0] == '复诊') {
                    alert("复诊不能进行返现操作！");
                    return;
                } else {
                    var customerId = $("#customerId").val();
                    var index = layer.open({
                        type: 2,
                        title: '返现操作',
                        area: ['40%', '60%'],
                        fix: true,
                        maxmin: true,
                        content: Feng.ctxPath + '/customer/returnCashTurnTo/' + customerId
                    });
                    this.layerIndex = index;
                }
            }
        });
    };

    //积分录入记录
    changeRecord = function () {
        var customerId = $("#customerId").val();
        var index = layer.open({
            type: 2,
            title: '积分录入记录',
            area: ['90%', '90%'],
            fix: true,
            maxmin: true,
            content: Feng.ctxPath + '/customer/changeRecord/' + customerId
        });
        this.layerIndex = index;
    };

    //返现记录
    returnCashRecords = function () {
        var customerId = $("#customerId").val();
        var index = layer.open({
            type: 2,
            title: '返现变更记录',
            area: ['90%', '90%'],
            fix: true,
            maxmin: true,
            content: Feng.ctxPath + '/customer/returnCashRecord/' + customerId
        });
        this.layerIndex = index;
    };

    //设置会员卡号
    settingMemberNum = function () {
        var customerId = $("#customerId").val();
        var index = layer.open({
            type: 2,
            title: '设置会员卡号',
            area: ['40%', '65%'],
            fix: true,
            maxmin: true,
            content: Feng.ctxPath + '/customer/to_settingMemberNum/' + customerId
        });
        this.layerIndex = index;
    };

    //积分兑换
    pointsFor = function () {
        var customerId = $("#customerId").val();
        var index = layer.open({
            type: 2,
            title: '积分兑换',
            area: ['40%', '60%'],
            fix: true,
            maxmin: true,
            content: Feng.ctxPath + '/customer/to_pointsFor/' + customerId
        });
        this.layerIndex = index;
    }
});